package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

type OnlineEventUser struct {
	ID                string `json:"id" gorm:"primaryKey;column:id;autoIncrement;type:bigint"`
	OnlineEventID     string `json:"online_event_id" gorm:"column:online_event_id;type:int;size:64;uniqueIndex:uk_join,priority:1"`
	UserID            string `json:"user_id" gorm:"column:user_id;type:int;size:64;comment:用户id"`
	OpenID            string `json:"openid" gorm:"column:openid;type:string;size:40;uniqueIndex:uk_join,priority:2"`
	WechatName        string `json:"wechat_name" gorm:"column:wechat_name;type:string;size:20;comment:微信名称"`
	Used_Points       int64  `json:"used_points" gorm:"column:used_points;type:int;size:64;comment:占用的积分"`
	RequireSupporters int    `json:"require_supporters" gorm:"column:require_supporters;type:int;size:32;comment:助力人数"`
	CurrentSupporters int    `json:"current_supporters" gorm:"column:current_supporters;type:int;size:32;comment:已助力人数"`
	UserName          string `json:"user_name" gorm:"column:user_name;type:string;size:30;comment:收件人姓名"`
	TelNumber         string `json:"tel_number" gorm:"column:tel_number;type:string;size:20;comment:收货人手机号"`
	PostalCode        string `json:"postal_code" gorm:"column:postal_code;type:string;size:255;comment:邮编"`
	ProvinceName      string `json:"province_name" gorm:"column:province_name;type:string;size:10;comment:国标收货地址第一级地址"`
	CityName          string `json:"city_name" gorm:"column:city_name;type:string;size:10;comment:国标收货地址第二级地址"`
	CountyName        string `json:"county_name" gorm:"column:county_name;type:string;size:20;comment:国标收货地址第三级地址"`
	StreetName        string `json:"street_name" gorm:"column:street_name;type:string;size:20;comment:国标收货地址第四级地址"`
	DetailAddress     string `json:"detail_address" gorm:"column:detail_address;type:string;size:50;comment:详细地址"`
	Status            int    `json:"status" gorm:"column:status;type:int;size:8;default:0;comment:0-已参与 1-申请成功 2-中奖 3-未中奖"`
	OutTradeNo        string `json:"out_trade_no" gorm:"column:out_trade_no;type:int;size:64;comment:订单交易号"`
	CreatedAt         int64  `json:"created_at" gorm:"column:created_at;autoCreateTime;type:int;size:64;index:idx_createdAt"`

	//是否是马甲用户
	IsPuppetUser bool `json:"is_puppet_user" gorm:"column:is_puppet_user;type:tinyint;size:1;default:0;comment:是否是马甲用户"`
}

func (OnlineEventUser) TableName() string {
	return "online_event_user"
}

// BeforeCreate 自增id
func (m *OnlineEventUser) BeforeCreate(tx *gorm.DB) (err error) {
	if m.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	m.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &OnlineEventUser{})
}
